package com.hospital.mapper;

import com.hospital.entity.Patient;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface PatientMapper {

    @Insert("INSERT INTO table_patient" +
            "(PATIENT_PASSWORD, PATIENT_NAME, PATIENT_GENDER, PATIENT_BIRTH, " +
            "PATIENT_IDCARD, PATIENT_MARRY, PATIENT_PHONE, PATIENT_PRIORITY, PATIENT_BLOCK)" +
            "VALUES(#{patient_password}, #{patient_name}, #{patient_gender}, #{patient_birth}, " +
            "#{patient_idcard}, #{patient_marry}, #{patient_phone}, #{patient_priority}, " +
            "#{patient_block})")
    int insertPatient(Patient patient);

    @Select("select * from table_patient where PATIENT_PHONE = #{phone}")
    Patient getPatientByPhone(String phone);

    @Select("select * from table_patient where PATIENT_IDCARD = #{idcard}")
    Patient getPatientByIdcard(String idcard);

    @Update("UPDATE table_patient SET PATIENT_PASSWORD=#{patient_password}," +
            "PATIENT_MARRY=#{patient_marry} " +
            "WHERE PATIENT_ID = #{patient_id}"
    )
    int updatePatient(Patient patient);

    @Update("UPDATE table_patient SET PATIENT_PRIORITY=#{priority} " +
            "WHERE PATIENT_ID = #{patient_id}"
    )
    int updatePriority(int patient_id, int priority);

    @Update("UPDATE table_patient SET PATIENT_PASSWORD=#{patient_password}," +
            "PATIENT_NAME=#{patient_name},PATIENT_BIRTH=#{patient_birth}," +
            "PATIENT_GENDER=#{patient_gender},PATIENT_PHONE=#{patient_phone}," +
            "PATIENT_IDCARD=#{patient_idcard},PATIENT_MARRY=#{patient_marry}," +
            "PATIENT_PRIORITY=#{patient_priority},PATIENT_BLOCK=#{patient_block} " +
            "WHERE PATIENT_ID = #{patient_id}"
    )
    int EX_updatePatient(Patient patient);
}
